//
// Created by Administrator on 2023/8/1.
//
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <cmath>


using namespace std;

class Solution {
public:
    bool checkXMatrix(vector<vector<int>> &grid) {
        int n = grid.size();
        // 如果是X 型的，则第i行的第i列和第n-i-1列值不是0，其他位置都是0
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j || i == n - j - 1) {
                    if (grid[i][j] == 0) {
                        return false;
                    }
                } else {
                    if (grid[i][j] != 0) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

};

int main(int argc, const char *argv[]) {

    vector<vector<int>> grid = {{1, 2, 3},
                                {4, 5, 6},
                                {7, 8, 9}};
    vector<vector<int>> grid2 = {{1, 0, 1},
                                 {0, 1, 0},
                                 {1, 0, 1}};
    Solution solution = Solution();
    bool result = solution.checkXMatrix(grid2);
    cout << result << endl;
    return 0;
}
